/**
 * 历史变更
 */
import store from '@/store';
import { log } from 'util';

const company = store.getters.companyInfo;
const dt = company.Company;

const ChangeList = dt.ChangeDiffInfo.ChangeList;
const HistoryDataList = dt.HistoryDataList;

const records = ChangeList.map((item, key) => {
  // 变更记录
  let left = '';
  if (key === 0) left = '变更记录';
  let order = key + 1;

  let before = item.BeforeList;
  let after = item.AfterList;

  return {
    left,
    children: [
      {
        left: `<em class="list-number">${
          order < 10 ? '0' + order : order
        }</em>`,
        content: item.ProjectName,
        link: '',
        icon: '',
        right: item.ChangeDate
      },
      {
        left: '',
        content: '',
        link: '',
        icon: '',
        right: '',
        change: { before, after }
      }
    ]
  };
});

const getList = (list, parent) => {
  const arr = [];

  list.map((item, index) => {
    // 变更记录
    let left = item.DataName;

    var obj = {
      left,
      children: [
        {
          left: '',
          content: item.DataName,
          link: '',
          icon: '',
          right: ''
        }
      ]
    };
    if (item.Children && item.Children.length > 0) {
      let child = item.Children.map((item, index) => {
        let order = index + 1;
        return {
          left: `<em class="list-number">${
            order < 10 ? '0' + order : order
          }</em>`,
          content: item.DataName,
          link: '',
          icon: '',
          right: ''
        };
      });
      obj.children = child;
    }
    arr.push(obj);
  });
  return arr;
};

const historyData = getList(HistoryDataList, 'parent');
console.log(historyData);

export default [...historyData, records];
